
// 152. 乘积最大子数组
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxProduct = function (nums) {
    if (nums.length === 1) return nums[0]
    /* minProductMemo:记录负数的情况，以免 -2, 3, -4 */
    const maxProductMemo = [nums[0]], minProductMemo = [nums[0]]
    let max = nums[0]
    for (let i = 1; i < nums.length; i++) {
        maxProductMemo[i] = Math.max(nums[i], nums[i] * maxProductMemo[i - 1], nums[i] * minProductMemo[i - 1])
        minProductMemo[i] = Math.min(nums[i], nums[i] * maxProductMemo[i - 1], nums[i] * minProductMemo[i - 1])
        max = Math.max(max, maxProductMemo[i])
    }
    return max
};
const result = maxProduct([-2, 3, -4])
console.log('result :>>', result);